home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cc02.arc / FUNKEY.C < prev    next >
Text File  |  1986-03-14  |  6KB  |  165 lines

  1.  
  2. /*           FUNKEY.C - a program for redefining fyunction keys  */
  3. /*                                                               */
  4. /*           Copyright  (C)  1983  Kenneth C. Wood               */
  5. /*                                                               */
  6. /*           From PC Magazine - - June 1983  Page 424            */
  7. /*                                                               */
  8. /*     Works with IBM PC-DOS 2.0 - to use it, have on your       */
  9. /*     system disk the files:                                    */
  10. /*     ANSI.SYS - supplied with DOS                              */
  11. /*     CONFIG.SYS - file with the line "device = ansi.sys" in it */
  12. /*     and one or more files with the extension .KEY i.e.        */
  13. /*     WORDSTAR.KEY, MYOWN.KEY, FUNKEY.KEY, or                   */
  14. /*     DOS.KEY - supplied by you and containing                  */
  15. /*     your chosen new key definitions, and of course            */
  16. /*     FUNKEY.EXE - the compiled and linked FUNKEY.C             */
  17. /*                                                               */
  18. /*     Now when the system is booted, the ANSI terminal          */
  19. /*     emulator device driver will be installed, giving          */
  20. /*     you the capability to do marvelous things, including      */
  21. /*     redefine the function keys by issuing the command:        */
  22. /*              FUNKEY MYOWN.KEY                                 */
  23.  
  24.  
  25. #define  SEQ "\033[0;"       /* Initial sequence to ANSI driver */
  26.  
  27. #include "stdio.h"          /* Copy in the standard I/O routines */
  28.  
  29. main(argc,argv)
  30. int argc;
  31. char *argv[];
  32.  
  33. {
  34.         FILE *fp, *fopen();
  35.  
  36.         if  (argc == 1)
  37.                 {
  38.                 printf("\nEnter new key definitions\n\n");
  39.                 fkey(stdin);         /* get input from keyboard */
  40.                 }
  41.         else
  42.                 {
  43.                 fp = fopen(*++argv,"r");
  44.                 fkey(fp);       /* get input from the file */
  45.                 }
  46. }
  47.  
  48. int count = 0;  /* counter for tracking size of the table */
  49.  
  50. fkey(fp)
  51. FILE *fp;
  52. {
  53.         int c,offset;
  54.         /* input character and function key identifier */
  55.  
  56.         while((c=getch(fp)) != EOF)
  57.         {
  58.                 switch (c)
  59.                 {
  60.                 case 'f':       /* F1 through F10 */
  61.                         offset = 58;
  62.                         func(getch(fp),offset,fp);
  63.                         break;
  64.                 case 's':       /* Shift F1 through F10 */
  65.                         offset = 83;
  66.                         func(getch(fp),offset,fp);
  67.                         break;
  68.                 case 'c':       /* Control F1 through F10 */
  69.                         offset = 93;
  70.                         func(getch(fp),offset,fp);
  71.                         break;
  72.                 case 'a':       /* Alt F1 through F10 */
  73.                         offset = 103;
  74.                         func(getch(fp),offset,fp);
  75.                         break;
  76.                 case 'F':       /* F1 through F10 */
  77.                         offset = 58;
  78.                         func(getch(fp),offset,fp);
  79.                         break;
  80.                 case 'S':       /* Shift F1 through F10 */
  81.                         offset = 83;
  82.                         func(getch(fp),offset,fp);
  83.                         break;
  84.                 case 'C':       /* Control F1 through F10 */
  85.                         offset = 93;
  86.                         func(getch(fp),offset,fp);
  87.                         break;
  88.                 case 'A':       /* Alt F1 through F10 */
  89.                         offset = 103;
  90.                         func(getch(fp),offset,fp);
  91.                         break;
  92.                 default:
  93.                         printf("Unknown function key\n");
  94.                         break;
  95.                 }
  96.         }
  97. }
  98.  
  99. getch(fp)
  100. /* throw away white space until a character */
  101. FILE *fp;
  102. {
  103. int x;
  104.  
  105.         while((x=getc(fp)) == ' '|| x == '\n' || x == '\t')
  106.                 ;       /* ignore white space */
  107.         return(x);
  108. }
  109.  
  110.  
  111. func(c,offset,fp)
  112. /* send out the required definition sequence */
  113. int c,offset;
  114. FILE  *fp;
  115. {
  116.         int x,save;
  117.  
  118.         save = ' ';
  119.         while ((x = getch(fp)) != '=')
  120.                 if (x == '0') c = ':';
  121.                 /* read until get = sign */
  122.                 /* if character is 0 then F10 was chosen */
  123.                 /* rather than F1.  Change c so that offset is */
  124.                 /* calculated correctly */
  125.         printf(SEQ);
  126.         printf("%d",offset+(c-'0'));
  127.  
  128. /*      putchar(';');
  129.         putchar('"');
  130. */
  131.         while ((x = getc(fp)) != '\n')
  132.                 {
  133.                 if (x != '!')
  134.                         {
  135. /*                      putchar(x);  */
  136.                         printf(";%2d",x);
  137.  
  138.                         if (++count == 128)
  139.                         {
  140.                 printf("\nTable size exceeded.  Program terminated...\n");
  141.                 exit();
  142.                         }
  143.                 }
  144.                 else
  145.                         save = x;
  146.         }
  147.         /*putchar('"');*/
  148.         if (save == '!')
  149.                 {
  150.                 printf(";13p");
  151.                 count++;
  152.                 }
  153.         else
  154.                 printf("p");
  155.         save = ' ';
  156.         if (count  == 128)
  157.         {
  158.                 printf("\nTable size exceeded.  Program terminated...\n");
  159.                 exit();
  160.         }
  161. }
  162.  
  163. /* end of Program Funkey.C  */
  164.  
  165.